# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ============================================================================
# Copyright 2021 Huawei Technologies Co., Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import numpy as np
import os
import tensorflow as tf
import math

FLAGS = tf.app.flags.FLAGS
tf.app.flags.DEFINE_string('label_dir', './SVHN/test_labels.npy', 'where to store the testlabel')
tf.app.flags.DEFINE_string('output_dir', './output/', 'where to store the test output txt')

if __name__ == '__main__': 
    label = np.load(FLAGS.label_dir).astype(np.float32)
    filelist = os.listdir(FLAGS.output_dir)
    filelist.sort()

    result = np.zeros(1)
    for i in range(0,len(filelist)):
        f = open(os.path.join(FLAGS.output_dir,filelist[i]))
        r = float(f.readline())
        if i ==0:
            result = r
        else:
            result =np.vstack((result,r))

    result = result.reshape(len(result))
    c = 0
    for i in range(0,len(result)):
        if result[i] == label[i]:
            c+=1
    print('ACC: ',c/len(result))
    
    